package com.daily.daily_push;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

public class test2ansible {
    public static void main(String[] args) throws IOException {
        String ansibleYamlName = "ansibalplaybook.yaml";
        String ansibleYamlName1 = "ansibalplaybook01.yaml";
       String playbookFile = "D:\\commonTest\\k8s\\autoYaml\\"+ansibleYamlName; // playbook文件路径
       String targetPlaybookFile = "D:\\commonTest\\k8s\\autoYaml\\"+ansibleYamlName1; // playbook文件路径

        // 从数据库获取变量值（此处仅为示例，您需要根据实际情况修改）
        String yamlPathValue = "/path/to/yaml/home";
        String targetYamlPathValue = "my-yaml-file.yaml";
        //要执行的k8s的yaml文件
        String yamlName = "mapptest.yaml";

        // 读取playbook文件内容
        String content = new String(Files.readAllBytes(Paths.get(playbookFile)), StandardCharsets.UTF_8);

        // 替换变量
        String replace = content.replace("hostsValue","master").replace("yamlPathValue", yamlPathValue).replace("targetYamlPathValue", targetYamlPathValue).replace("yamlName", yamlName);
        content.replace("hostsValue","master");
        // 将更新后的内容写回文件
        Files.write(Paths.get(targetPlaybookFile), replace.getBytes(StandardCharsets.UTF_8));


    }



}
